package com.qzsf.backend.mapper;

import com.qzsf.backend.common.Result;
import com.qzsf.backend.dto.ParticipationCreateDTO;
import com.qzsf.backend.entity.Participation;
import com.qzsf.backend.mapper.sql.OrganizerSqlProvider;
import com.qzsf.backend.mapper.sql.ParticipationSqlProvider;
import com.qzsf.backend.vo.ParticipationMobileVO;
import com.qzsf.backend.vo.ParticipationVO;
import com.qzsf.backend.vo.RegistrationBriefVO;
import com.qzsf.backend.vo.UserBriefVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.springframework.stereotype.Repository;

import java.util.List;

/*
 * @Author: Dennis Chen
 * @CreateTime: 2024/11/25 15:13 周一
 * @Email 1429278462@qq.com
 * @Remark 参与情况数据访问层
 * @Version 1.0
 */
@Mapper
@Repository
public interface ParticipationMapper {
    @SelectProvider(type = ParticipationSqlProvider.class, method = "getParticipationByCondition")
    List<ParticipationVO> getParticipation(String userName,String eventName);

    @Select("select * from participation where user_id = #{id} and event_id = #{eventId}")
    Participation getParticipationByUserAndEvent(int id,int eventId);

    @Select("select count(*) from participation where event_id = #{eventId}")
    int getEventParticipationNum(int eventId);

    @Select("SELECT a.user_id as userId,c.name as userName,c.pic,a.event_id as eventId,d.name as eventName,d.hours FROM registration a LEFT JOIN participation b ON a.user_id = b.user_id AND a.event_id = b.event_id left join user_profile c on a.user_id = c.id left join event d on a.event_id = d.id WHERE b.id IS NULL and a.event_id = #{eventId};")
    List<ParticipationMobileVO> getUsersWithIncompleteParticipation(int eventId);

    void batchInsertParticipation(List<ParticipationCreateDTO> participationList);

    void batchInsertUnParticipation(List<ParticipationCreateDTO> participationList);

    @Delete("delete from participation where id = #{id}")
    int deleteParticipationById(int id);
}
